//
//  ZTEOnlineDoc.m
//  ZTEOnlineDoc
//
//  Created by 万伟琦 on 2018/9/6.
//  Copyright © 2018年 万伟琦. All rights reserved.
//

#import "ZTEOnlineDoc.h"
#import "ZODPreviewController.h"
#import "ZODViewInfo.h"
#import "ZODHTTPManager.h"
#import "ZODPreConvertInfo.h"
#import "ZODNetworkRequest.h"
#import "ZODOnlineDocConfiguration.h"
#import "ZODAttInfo.h"
#import "ZODGlobalStorage.h"
#import "ZODInternalTools.h"

@interface ZTEOnlineDoc ()

@property (nonatomic) ZODOnlineDocConfiguration *configuration;


@end

@implementation ZTEOnlineDoc

- (instancetype)initWithConfiguration:(ZODOnlineDocConfiguration *)configuration {
    if (self = [super init]) {
        _configuration = configuration;
        [ZODGlobalStorage sharedStorage].configuration = configuration;
    }
    return self;
}


- (void)preConvertWithFiles:(NSArray<ZODAttInfo *> *)files {
    NSString *baseUrlStr = [ZODGlobalStorage sharedStorage].preConvertBaseURLString;
    NSString *sysCode = self.configuration.sysCode;
    NSString *uno = self.configuration.userNo;
    
    NSMutableArray *fileInfos = [NSMutableArray array];
    for (ZODAttInfo *attInfo in files) {
        ZODFileInfo* fileInfo = [ZODInternalTools getFileInfoFromAttInfo:attInfo];
        [fileInfos addObject:fileInfo];
    }
    
    [ZODNetworkRequest requestPreConversionWithBaseURL:baseUrlStr Files:fileInfos sysCode:sysCode userNo:uno success:^{
        
    } failure:^(NSError * _Nonnull error, NSString * _Nonnull errorCode) {
        
    }];
}


- (UIViewController *)getPreviewControllerWithAttInfo:(ZODAttInfo *)attInfo{
    
    ZODPreviewController *vc = [[ZODPreviewController alloc] initWithConfiguration:self.configuration attInfo:attInfo];
    
    return vc;
}


@end
